package com.lwm.controller;

import com.github.pagehelper.PageInfo;
import com.lwm.domain.EarlyWarning;
import com.lwm.domain.ResponseResult;
import com.lwm.service.EarlyWarningService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 能效预警控制层
 */
@RestController
@RequestMapping("/earlyWarning")
@Slf4j
public class EarlyWarningController {
    @Resource
    private EarlyWarningService earlyWarningService;

    /**
     * 保存
     *
     * @param earlyWarning 能效预警实体类
     * @return {@link ResponseResult}<{@link Object}>
     */
    @PostMapping
    public ResponseResult<Object> save(@RequestBody EarlyWarning earlyWarning) {
        return earlyWarningService.save(earlyWarning);
    }

    /**
     * 删除
     *
     * @param ids id集合
     * @return {@link ResponseResult}<{@link Object}>
     */
    @DeleteMapping
    public ResponseResult<Object> remove(@RequestBody List<Long> ids) {
        return earlyWarningService.remove(ids);
    }

    /**
     * 编辑
     *
     * @param earlyWarning 能效预警实体类
     * @return {@link ResponseResult}<{@link Object}>
     */
    @PutMapping
    public ResponseResult<Object> edit(@RequestBody EarlyWarning earlyWarning) {
        return earlyWarningService.edit(earlyWarning);
    }

    /**
     * 分页
     *
     * @param earlyWarning 能效预警实体类(条件查询参数封装)
     * @param page         页码
     * @param size         数量
     * @return {@link ResponseResult}<{@link PageInfo}<{@link EarlyWarning}>>
     */
    @GetMapping("/page")
    public ResponseResult<PageInfo<EarlyWarning>> page(Integer page, Integer size, EarlyWarning earlyWarning) {
        return earlyWarningService.page(page, size, earlyWarning);
    }

    /**
     * 根据id获取
     *
     * @return {@link ResponseResult}<{@link Object}>
     */
    @GetMapping("/{id}")
    public ResponseResult<Object> getById(@PathVariable Long id) {
        log.info("id {}", id);
        return earlyWarningService.getById(id);
    }
}
